<script>
  // 箱平台字典混合 2018/9/3 zhangQ
  import { getSenderList, getReceiverList, getContainerOwnerList } from '@/api/containerPlatform/logistics'
  import { getStateList, getContainersPositionList, getContainersTypeList } from '@api/containerPlatform/containerManagement'
  import pinyin from '@components/common/pinyin'
  import _ from 'lodash'

  export default {
    data () {
      let senderDict = []
      let receiverDict = []
      let stationCodesDict = []
      let curStateIdsDict = []
      let containerTypesDict = []
      let containerUsersDict = []
      let datas = { senderDict, receiverDict, stationCodesDict, curStateIdsDict, containerTypesDict, containerUsersDict }
      return datas
    },
    computed: {},
    methods: {
      /**
       * TODO(获得箱属列表)
       * @auther zhangQ
       * @date 2018/9/3 16:53
       */
      getContainerOwnerListDB () {
        getContainerOwnerList()
          .then(res => {
            if (res.data.isSuccess === 1) {
              let resData = []
              res.data.data.forEach((item) => {
                let py = pinyin.codefans_net_CC2PY(item)
                resData.push({
                  py: py,
                  containerOwner: item
                })
              })
              this.containerUsersDict = resData
            }
          })
      },
      /**
       * TODO(获取状态列表)
       * @auther zhangQ
       * @date 2018/9/3 16:48
       */
      getStateListDB () {
        getStateList()
          .then(res => {
            if (res.data.isSuccess === 1) {
              // 30 31 在途 80出局 其他站内
              let stateGroup = _.groupBy(res.data.data, (item) => {
                if (+item.id === 30 || +item.id === 31) {
                  return '在途'
                } else if (+item.id === 80) {
                  return '出局'
                } else if (+item.id !== 99) {
                  return '站内'
                } else {
                  return '99'
                }
              })
              let resData = []
              _.forIn(stateGroup, (value, key) => {
                if (+key !== 99) {
                  resData.push({ key: key, value: value })
                }
              })
              this.curStateIdsDict = resData
            }
          })
      },
      /**
       * TODO(获得箱形列表)
       * @auther zhangQ
       * @date 2018/9/3 16:50
       */
      getContainersTypeListDB () {
        getContainersTypeList()
          .then(res => {
            if (res.data.isSuccess === 1) {
              let resData = []
              res.data.data.forEach((item) => {
                let py = pinyin.codefans_net_CC2PY(item)
                resData.push({
                  py: py,
                  containerType: item
                })
              })
              this.containerTypesDict = resData.reverse()
            }
          })
      },
      /**
       * TODO(获取场站位置信息)
       * @auther zhangQ
       * @date 2018/9/3 16:47
       */
      getContainersPositionListDB () {
        getContainersPositionList({ isAll: 0 }).then(res => {
          if (res.data.isSuccess === 1) {
            let resData = []
            res.data.data.forEach((item) => {
              let py = pinyin.codefans_net_CC2PY(item)
              resData.push({
                py: py,
                stationName: item
              })
            })
            this.stationCodesDict = resData
          }
        })
      },
      /**
       * TODO(获取发送人列表)
       * @auther zhangQ
       * @date 2018/9/3 16:47
       */
      getSenderListDB () {
        getSenderList()
          .then(res => {
            if (+res.data.isSuccess === 1) {
              this.senderDict = res.data.data
            }
          })
      },
      /**
       * TODO(获取收货人列表)
       * @auther zhangQ
       * @date 2018/9/3 16:47
       */
      getReceiverListDB () {
        getReceiverList()
          .then(res => {
            if (+res.data.isSuccess === 1) {
              this.receiverDict = res.data.data
            }
          })
      }
    },
    created () {
    },
    mounted () {
    },
    components: {}
  }
</script>
